*******************************************************************
* This file generates the information in Table 3, Panels A and B. *
*******************************************************************
* 1. Summarize the data observed at the notary level
* 2. Summarize the tract-level data

*************************
* 0 Set path to files *
*************************
clear all
capture log close
set more off
set trace off
cd $main_directory
use "Data_Belgium/Generated_data/BE_notary_data.dta", clear

***********************************************************************
* 1. Summarize the data observed at the notary level: Table 3 Panel A *
***********************************************************************
//Transactions
su Q Q1 Q2, de
//Hours FTE and staff costs
su HoursFTE StaffCostFTE, de
//Intermediate inputs
su IntDM2, de
//Fixed costs as depreciation and amortization (=EBITDA-EBIT)
gen DA=EBITDA-EBIT
su DA if DA>0, de
gen DAPerNot=DA/NotPerOff
su DAPerNot if DAPerNot>0, de
//Net added value
su NAddVal, de
//Notaries per office
su NotPerOff, de

//Calculate date as years elapsed since 1 Jan 1999
format StartDate_off %td //start date of head office from Belfirst
format Time_since_operation1 %td //start date of notary from Belgian website (including predecessors)
replace StartDate_off=18993 if StartDate_off==. //arbitrarily at 1 Jan 2012
replace StartDate_off=14245 if StartDate_off<14245 //arbitarily truncate at 1 Jan 1999
gen start_not=(StartDate_off-14245)/365 //time since 1 Jan 1999 in decimals
su start_not, de

//Calculate company type
gen LDE=Lf==5 //Legal Form is "LDE", non-limited liability firm, almost always single person offices
su LDE, de


********************************************************
* * 2. Summarize the tract-level data: Table 3 Panel B *
********************************************************
use "Data_Belgium/Generated_data/BE_municipal_data.dta", clear
su log_income popdens Perc_Young Perc_Elderly, de

*Panel C of Table 3 requires the generation of the long demand dataset, which is done in the next file.
